//
//  LJCCategoryViewController.m
//  WZLProduct
//
//  Created by 陆静聪 on 16/3/18.
//  Copyright © 2016年 HaiTeng. All rights reserved.
//

#define KEYHEADER @"3590069"
#import "LJCCategoryViewController.h"

@interface LJCCategoryViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *rootTable;/**< 底层table */
@property (nonatomic, retain) NSString *pageNum;/**< 刷新页数 */
@property (nonatomic, retain) NSMutableArray *dataArr;/**< 数据总数组 */

@end

@implementation LJCCategoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.hidden = NO;
    [self createTable];
    
    [self dataHandel];
}

/** 解析数据 */
- (void)dataHandel {

    
    [LJCAFN POSTWithURL:@"http://api.pianke.me/version4.0/ting/listByStyle.php?sig=C8A19B606DE32C542DF303BC819B482B" prefix:KEYHEADER par:@{@"pageSize" : @"10" , @"style" : [NSString stringWithFormat:@"%ld", _index.row + 1], @"pageNum" : @"1"} success:^(id response) {
        _dataArr = [LJCMusicModel modelHandleWithModel:response[@"data"]];

        [_rootTable reloadData];
    } filed:^(NSError *err) {
        
    }];
}

/** 创建table */
- (void)createTable {
    _rootTable = [[UITableView alloc] initWithFrame:kScreen style:UITableViewStylePlain];
    _rootTable.delegate = self;
    _rootTable.dataSource = self;
    _rootTable.rowHeight = 75;
    [self.view addSubview:_rootTable];
    
    [_rootTable registerClass:[LJCMusicTableViewCell class] forCellReuseIdentifier:@"LJCMusicTableViewCell"];
}

#pragma mark - tableView代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LJCMusicTableViewCell *musicTableCell = [tableView dequeueReusableCellWithIdentifier:@"LJCMusicTableViewCell"];
    musicTableCell.categoryModel = _dataArr[indexPath.row];

    return musicTableCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    LJCMusicViewController *MVC = [[LJCMusicViewController alloc] init];
    [MVC getUrlArr:_dataArr indexPath:indexPath.row];
    [self.navigationController pushViewController:MVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
